package com.elite.groovy.callback;

import groovy.json.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.RequestDispatcher;
import com.elite.groovy.util.EliteBean;
import java.security.MessageDigest;
import java.sql.ResultSet;
import java.text.SimpleDateFormat;

import net.sf.json.JSONObject;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.wisdge.dataservice.Result;
import com.elite.groovy.util.Util;
import cn.com.kh.HttpClientProxy;
import org.apache.commons.lang.StringEscapeUtils;

public class TaiPingInterface implements ServiceBackInvoke{
	private static final Log log=LogFactory.getLog(TaiPingInterface.class);

	public String doCallBack(EliteBean eliteBean,HttpServletRequest request,HttpServletResponse response) {


		response.setCharacterEncoding("UTF-8");
		log.debug("apiInterfaceTest start-----------------");
		log.debug("apiInterfaceTest request----------------:"+request);
		
		String requestUrl=request.getRequestURL().toString();

		String getMethod = request.getMethod();
		String callJson="";
		BufferedReader iny = null;				
		def reJson = "";
		log.debug("apiInterfaceTest getMethod:"+getMethod);
		if (getMethod.equals("GET")) {
			callJson = request.getParameter("jsondata");
		} else {
			InputStreamReader reader = new InputStreamReader(request.getInputStream(), "UTF-8");
			iny = new BufferedReader(reader);
			String line;
			while ((line = iny.readLine()) != null) {
				callJson += line;
			}
		}
		log.debug("apiInterfaceTest callJson:"+callJson);
		
		
        reJson = HttpClientProxy.sendPost("http://bdcapi.ccod.com:18086/agent/user/" +        	  request.getParameter("requestType"),callJson,"10.28.178.1",31151);
				
		/* 测试使用
		reJson = HttpClientProxy.sendPost("http://gateway.cs.ccod.com:8088/agent/dps/query",callJson,"172.30.30.12",40000);
		*/	
		
		if(reJson.length()<=0 || reJson==null){
		   reJson="{\"code\":-1,\"msg\":\"转发服务请求异常!\"}";
		}
		
		/*
		String rejsontwo=StringEscapeUtils.unescapeJavaScript(reJson);
		log.debug("json斜杠处理："+rejsontwo);
		*/
		
		return reJson;
		
	}

}